\subsection{Symbols}

As we saw earlier, symbols are defined using an equals sign.

\begin{Verbatim}[formatcom=\color{blue}]
N = 212^17
\end{Verbatim}

\noindent
No result is printed when a symbol is defined.
To see the value of a symbol, just evaluate it.

\begin{Verbatim}[formatcom=\color{blue}]
N
\end{Verbatim}

\noindent
$\displaystyle N=3529471145760275132301897342055866171392$

\bigskip
\noindent
Symbols can have more that one letter.
Everything after the first letter is displayed as a subscript.

\begin{Verbatim}[formatcom=\color{blue}]
NA = 6.02214 10^23
NA
\end{Verbatim}

\noindent
$\displaystyle N_A=6.02214\times10^{23}$

\bigskip
\noindent
A symbol can be the name of a Greek letter.

\begin{Verbatim}[formatcom=\color{blue}]
xi = 1/2
xi
\end{Verbatim}

\noindent
$\displaystyle \xi=\tfrac{1}{2}$

\bigskip
\noindent
Greek letters can appear in subscripts.

\begin{Verbatim}[formatcom=\color{blue}]
Amu = 2.0
Amu
\end{Verbatim}

\noindent
$\displaystyle A_\mu=2.0$

\bigskip
\noindent
The following example shows how
Eigenmath scans the entire symbol to find Greek letters.

\begin{Verbatim}[formatcom=\color{blue}]
alphamunu = 1
alphamunu
\end{Verbatim}

\noindent
$\displaystyle \alpha_{\mu\nu}=1$

\bigskip
\noindent
When a symbolic chain is defined,
Eigenmath follows the chain as far as possible.
The following example sets $A=B$ followed by $B=C$.
Then when $A$ is evaluated, the result is $C$.

\begin{Verbatim}[formatcom=\color{blue}]
A = B
B = C
A
\end{Verbatim}

\noindent
$\displaystyle A=C$

\bigskip
\noindent
Although $A=C$ is printed,
inside the program the binding of $A$ is still $B$, as can be seen with
the $binding$ function.

\begin{Verbatim}[formatcom=\color{blue}]
binding(A)
\end{Verbatim}

\noindent
$\displaystyle B$

\bigskip
\noindent
The {\it quote} function returns its argument unevaluated
and can be used to clear a symbol.
The following example clears $A$ so that its evaluation goes back to
being $A$ instead of $C$.

\begin{Verbatim}[formatcom=\color{blue}]
A = quote(A)
A
\end{Verbatim}

\noindent
$\displaystyle A$

\subsection{User defined functions}

Most of the functions commonly used in math and physics are included in Eigenmath.
See the Reference section at the end of the manual for a complete list.
There is also a facility for the user to define additional functions.

\bigskip
\noindent
User functions are defined using the syntax {\it function-name} ( {\it arg-list} ) = {\it expr}.
The {\it arg-list} is an optional comma separated list of symbols that receive arguments.
Unlike symbolic definitions, {\it expr} is not evaluated when {\it function-name} is defined.
Instead, {\it expr} is evaluated when {\it function-name} is used in a subsequent computation.

\bigskip
\noindent
The following example defines a sinc function and evaluates it at $\pi/2$.

\begin{Verbatim}[formatcom=\color{blue}]
f(x) = sin(x)/x
f(pi/2)
\end{Verbatim}

\noindent
$\displaystyle \frac{2}{\pi}$

\bigskip
\noindent
After a user function is defined, {\it expr} can be recalled using the {\it binding} function.

\begin{Verbatim}[formatcom=\color{blue}]
binding(f)
\end{Verbatim}

\noindent
$\displaystyle \frac{\sin(x)}{x}$

\bigskip
\noindent
The following example uses Rodrigues's formula to
compute an associated Legendre function of $\cos\theta$.
\begin{equation*}
P_l^m(x)=\frac{1}{2^ll!}(1-x^2)^{m/2}\frac{d^{l+m}}{dx^{l+m}}(x^2-1)^l
\end{equation*}
The formula is computed for $x$ and then
{\it eval} replaces $x$ in the result with $\cos\theta$.

\begin{Verbatim}[formatcom=\color{blue}]
P(l,m) = eval(1/(2^l l!) (1 - x^2)^(m/2) d((x^2 - 1)^l,x,l + m),x,cos(theta))
P(2,0)
\end{Verbatim}

\noindent
$\displaystyle \tfrac{3}{2} \cos(\theta)^2-\tfrac{1}{2}$

\bigskip
\noindent
When a user function is evaluated, the function arguments are visible
to any symbol definitions that reference them.
The symbol definitions can appear either before or after the function definition.
In the following example, the $x$ in $A$ and $B$ is replaced with $y$.

\begin{Verbatim}[formatcom=\color{blue}]
f(x) = A + B
A = a x
B = b x
f(y)
\end{Verbatim}

\noindent
$\displaystyle ay+by$
